<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">{{ settings.title }}</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: fromRouter.path }" v-if="secondNameVisible">{{ secondTitle }}</el-breadcrumb-item>
      <slot></slot>
    </el-breadcrumb>
  </div>
</template>

<script>
import settings from '@/settings';
import { getDynamicTitle } from '@/utils/dictUtil';
import { mapGetters } from 'vuex';
export default {
  name: 'LkBreadcrumb',
  props: {
    showPrev: {
      type: String,
      default: ''
    }
  },
  components: {},
  // 定义属性
  data () {
    return {
      fromRouter: {
        title: '',
        path: '',
        name: '',
        params: {},
        meta: {}
      },
      settings
    };
  },
  computed: {
    ...mapGetters({
      dictionary: 'dictionary/get'
    }),
    secondNameVisible () {
      if (this.showPrev) {
        if (this.fromRouter.name && this.fromRouter.name.includes(this.showPrev)) {
          return true;
        }
      }
      return false;
    },
    secondTitle () {
      if (this.fromRouter.name === 'seniorList') {
        const dynamicTitle = getDynamicTitle(this.fromRouter, this.dictionary);
        return dynamicTitle;
      } else {
        return this.fromRouter.title;
      }
    }
  },
  // 方法集合
  methods: {

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created () {
    this.fromRouter = JSON.parse(localStorage.getItem('fromRouter'))[0];
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {

  },
  beforeCreate () {}, // 生命周期 - 创建之前
  beforeMount () {}, // 生命周期 - 挂载之前
  beforeUpdate () {}, // 生命周期 - 更新之前
  updated () {}, // 生命周期 - 更新之后
  beforeDestroy () {}, // 生命周期 - 销毁之前
  destroyed () {}, // 生命周期 - 销毁完成
  activated () {} // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
